import { ref, onMounted, watch } from "vue";
import axios from "axios";
export default function () {
  //功能2-初始化数据
  const imgUrl = ref("");
  //功能2-事件回调函数
  const randomDog = async () => {
    const result = await axios.get(`https://dog.ceo/api/breeds/image/random`);
    imgUrl.value = result.data.message;
  };
  //功能2-初始化
  onMounted(() => {
    console.log("功能2初始化");
  });
  //功能2-监视
  watch(imgUrl, () => {
    console.log("又请求了一个狗的照片");
  });

  return {
    imgUrl,
    randomDog,
  };
}